<!-- html -->
<template>
	<view class="page">
		<view class="between">
			<view class="title">
				发现
			</view>
			<uni-icons type="search" size="30" color="#787B86"></uni-icons>
		</view>
		<scroll-view :scroll-y="true" class="scroll-Y" @scrolltolower="lower" style="height: 100vh;">
			<view class="left">
				<item v-for="(item, index) in leftList" :key="index" :item="item"> </item>
			</view>
			<view class="right">
				<item v-for="(item, index) in rightList" :key="index"  :item="item"> </item>
			</view>
		</scroll-view>
	</view>
</template>


<script>
	var res;
	import item from './core/item.vue'
	export default {
		components: {
			item
		},
		data() {
			return {
				// 图片列表
				list: [],
				// 初始化左右盒子
				leftList: [],
				rightList: [],
				// 初始化左右盒子高度
				leftH: 0,
				rightH: 0
			};
		},
		onLoad() {
			this.getData([]);
		},
		methods: {
			async getData(data) {
				res = await this.service.list({});
				
				this.list = this.list.concat(res.data)
				this.doList()
			},
			lower() {
				this.getData();
			},
			doList() {
				const that = this;
				this.list.forEach(res => {
					// 获取图片宽高
					uni.getImageInfo({
						src: res.img,
						success: image => {
							console.log(res.src);
							// 计算图片渲染高度
							let showH = (50 * image.height) / image.width;
							// 判断左右盒子高度
							if (that.leftH <= that.rightH) {
								that.leftList.push(res);
								that.leftH += showH;
							} else {
								that.rightList.push(res);
								that.rightH += showH;
							}
						}
					});
				});
			}
		}
	};
</script>
<style lang="scss" scoped>
	.page {
		padding: 20px 20px 0px 20px;

		.between {
			padding-bottom: 10px;

			.title {
				font-size: 40rpx;

				color: #232832;
			}
		}
	}

	.container {
		padding: 0 30rpx;
		font-size: 14rpx;
		line-height: 24rpx;
	}

	.right,
	.left {
		display: inline-block;
		width: 49%;
		vertical-align: top;
	}

	.left {
		margin-right: 2%;
	}

	.left image,
	.right image {
		width: 100%;
		margin-bottom: 10rpx;
	}
</style>
